<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<s:head theme="ajax"/>
<style type="text/css">
hr{
	margin-top: 0px;
	margin-bottom: 0px;
}
</style>
</head>
<body>
	<center>
		<table border="0" width="100%" height="100%">
			<caption>				
				<s:if test="type==1"><font size="4"><b>개인 주소록</b></font></s:if>
				<s:else><font size="4"><b>부서공용 주소록</b></font></s:else>				
			</caption>			
			<tr>
				<th colspan="6" align="left">
					<%--초성 검색 링크 생성용 배열 --%>
					 <c:set var="heads" scope="request">
					 ㄱ, ㄴ, ㄷ, ㄹ, ㅁ, ㅂ, ㅅ, ㅇ, ㅈ, ㅊ, ㅋ, ㅌ, ㅍ, ㅎ
					 </c:set>
					 <c:forEach var="hd" items="${heads }">
					 	<%--한글 깨지면 톰캣 server.xml에 Connector태그에 URIEncoding="UTF-8" 추가 --%>
					 	<s:url id="chosungURL" action="find" namespace="/addrbook">
					 		<s:param name="fword">chosung</s:param>
					 		<s:param name="sword">${hd }</s:param>					 		
					 	</s:url>
					 	<s:a href="%{chosungURL}" theme="ajax" targets="abcontents" onmouseover="this.style.backgroundColor='#eaf0fa'"  onmouseout="this.style.backgroundColor=''">
					 	${hd }</s:a>
					 </c:forEach>
				</th>
			</tr>
			<tr>
				<td colspan="6"><hr class="#6666FF"></td>				
			</tr>
			<tr>
				<td width="7%">
					<%--전체 선택 체크박스 --%>
					<input type="checkbox" id="abChkAll" onclick="javascript:abCheckAll()">
				</td>
				<td width="17%">이름</td>
				<td width="19%">휴대폰</td>
				<td width="19%">일반전화</td>
				<td width="19%">이메일</td>
				<td width="19%">회사명</td>				
			</tr>
			<tr>
				<td colspan="6">
					<hr>
					<form id="chkfrm" action="/ssteam/addrbook/deleteSelected.team" method="post">
						<%--폼 서브밋 전에 선택된 check의 value를 하나의 값으로 합쳐 저장 (ex - 1|2|10) --%>
						<input type="hidden" id="selected" name="selected" value="">
					</form>
				</td>
			</tr>
			<s:iterator value="ablist">
			<tr onmouseover="this.style.backgroundColor='#eaf0fa'" onmouseout="this.style.backgroundColor=''">
				<td>
					<%--
						id는 자바스크립트에서 식별용, value는 실질적인 삭제 처리용 값, 
						name은 check를 그룹으로 불러 들일때 사용 
					--%>
					<input type="checkbox" id="ab${addrno }" value="${addrno }" name="abchks">
				</td>
				<td>									
					<s:url id="conURL" namespace="/addrbook" action="content">
						<s:param name="addrno">${addrno }</s:param>
						<s:param name="curpage">${curpage }</s:param>
					</s:url>
					<s:a href="%{conURL}" theme="ajax" targets="abcontents">
					${name }
					</s:a>
				</td>
				<td>${hp }</td>
				<td>${tel }</td>
				<td>${email }</td>
				<td>${company }</td>
			</tr>
			<tr>
				<td colspan="6"><hr></td>
			</tr>
			</s:iterator>
			<tr>
				<td colspan="6" align="right">
					<s:a href="/ssteam/addrbook/insert.team?type=%{#request['type']}" targets="abcontents" theme="ajax">
						<img src="/ssteam/image/addrbook/ab_button_insert.png" border="0">
					</s:a>
					&nbsp;
					<%--선택 삭제 --%>
					<%--
						폼 실행전에 onclick에 설정한 자바스크립트가 먼저 실행된다
						selectedToValue()는 전체 check 목록 중에 선택된 check의 value를 |를 식별자로
						합쳐 히든타입의 value로 저장한다 (ex - 10, 11번 선택시 -> 10|11|)
					 --%>
					<s:a formId="chkfrm" targets="abcontents" theme="ajax" onclick="selectedToValue()" showLoadingText="false">
						<img src="/ssteam/image/addrbook/ab_button_delete.png" border="0">
					</s:a>
				</td>
			</tr>
			<tr>
				<td colspan="6" align="center">
					<%--페이지 구분 --%>									
					<c:forEach begin="1" end="${totalpage }" step="1" var="i">						
						<s:url id="ablURL" action="%{#request.abAction}" namespace="/addrbook">
					 		<s:param name="fword">${fword }</s:param>
					 		<s:param name="sword">${sword }</s:param>						
							<s:param name="type">${type }</s:param>
							<s:param name="sabun">${session.user.sabun }</s:param>
							<s:param name="curpage">${i }</s:param>
						</s:url>
						<s:a href="%{ablURL}" theme="ajax" targets="abcontents">[${i }]&nbsp;</s:a>
					</c:forEach>
				</td>
			</tr>			
			<tr>
				<td colspan="6" align="center">					
					<form id="findfrm" action="/ssteam/addrbook/find.team" method="post">
					<input type="hidden" name="type" value="${type }">
					<select name="fword">						
						<option value="name">이름</option>
						<option value="tel">전화</option>
						<option value="hp">휴대전화</option>
						<option value="email">이메일</option>
					</select>
					<input type="text" size="20" name="sword">					
					<s:a formId="findfrm" theme="ajax" targets="abcontents" showLoadingText="false">
						<img src="/ssteam/image/addrbook/ab_button_find.png" border="0" align="middle">
					</s:a>
					</form> 
					<%--Ajax를 이용한 Form 전송시 showLoadingText="false"옵션 필수 --%>					
				</td>
			</tr>						
		</table>
	</center>
</body>
</html>